/*
 * GerenciadorFinanceiroApp.java
 */

package gerenciadorfinanceiro;

import gerenciadorfinanceiro.view.resources.BalanceteAnual;
import gerenciadorfinanceiro.view.resources.BalanceteMensal;
import gerenciadorfinanceiro.view.resources.CadastrarDespesa;
import gerenciadorfinanceiro.view.resources.CadastrarReceita;
import gerenciadorfinanceiro.view.resources.ConsultarDespesas;
import gerenciadorfinanceiro.view.resources.ConsultarReceitas;
import gerenciadorfinanceiro.view.resources.ImportarDados;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * The main class of the application.
 */
public class GerenciadorFinanceiroApp extends SingleFrameApplication {

    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        GerenciadorFinanceiroView mainForm = new GerenciadorFinanceiroView(this);
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        mainForm.setUtil((Utilitario)context.getBean("utils"));
        mainForm.setFormCadastrarDespesa((CadastrarDespesa)context.getBean("formCadastrarDespesa"));
        mainForm.setFormCadastrarReceita((CadastrarReceita)context.getBean("formCadastrarReceita"));
        mainForm.setBalanceteMensal((BalanceteMensal)context.getBean("formBalanceteMensal"));
        mainForm.setBalanceteAnual((BalanceteAnual)context.getBean("formBalanceteAnual"));
        mainForm.setConsultarDespesas((ConsultarDespesas)context.getBean("formPesquisarDespesa"));
        mainForm.setConsultarReceitas((ConsultarReceitas)context.getBean("formPesquisarReceita"));
        mainForm.setImportarDados((ImportarDados)context.getBean("formImportarDados"));

        mainForm.carregarEstatisticas();

        show(mainForm);
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of GerenciadorFinanceiroApp
     */
    public static GerenciadorFinanceiroApp getApplication() {
        return Application.getInstance(GerenciadorFinanceiroApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(GerenciadorFinanceiroApp.class, args);
    }
}
